package com.awenhui.demo.study;

import org.springframework.util.StringUtils;

/**
 * @author yuxf
 * @version 1.0
 * @date 2020/9/21 9:35
 */
public class StudyDemo {

    public static void main(String[] args) {
        String szg0252 = getMaxCode("", 1);
        System.out.println(szg0252);
    }

    public  static  String getMaxCode(String maxCode,Integer type)
    {

        if (StringUtils.isEmpty(maxCode)) {
            switch (type.intValue()) {
                case 1:
                    maxCode = "SZG2018-0001";
                    break;
                case 2:
                    maxCode = "SZG2018-0001";
                    break;
                case 3:
                    maxCode = "ZC-KF-00000001";
                    break;
                case 4:
                    maxCode = "ZC-DH-00000001";
                    break;
                case 5:
                    maxCode = "ZC-BG-00000001";
                    break;
                case 6:
                    maxCode = "ZC-GG-00000001";
                    break;
                case 7:
                    maxCode = "GGFY-000000001";
                    break;
                case 8:
                    maxCode = "ZTMTDQ2020-0001";
                    break;
                case 9:
                    maxCode = "ZTMTGJ2020-0001";
                    break;
                default:
                    break;
            }
        }
        //取出最后一个数字索引
        int sub = 0;
        for (int i = maxCode.length() - 1; i >= 0; i--) {
            char charAt = maxCode.charAt(i);
            if (!Character.isDigit(charAt)) {
                sub = i;
                break;
            }
        }
        sub += 1;
        //截取最后一个数字后的字符
        String sbDigit = maxCode.substring(sub, maxCode.length());
        //截取最后一个数字前的字符
        String sbNotDigit = maxCode.substring(0, sub);
        //
        Long parseInt = Long.parseLong(sbDigit) + 1;
        String digitStr = parseInt.toString();
        int digitLength = maxCode.length() - sub;
        StringBuffer sb = new StringBuffer();
        if (digitStr.length() < digitLength) {
            int digitLength2 = digitLength - digitStr.length();
            for (int i = 0; i < digitLength2; i++) {
                sb.append("0");
            }
        }

        return maxCode;
    }
}
